home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 2- playing movie / source / zoo2.java
Encoding:
Java Source  |  2000-06-23  |  4.8 KB  |  138 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.io.IOException;
  4.  
  5. import quicktime.QTSession;
  6. import quicktime.QTException;
  7.  
  8. import quicktime.app.image.GraphicsImporterDrawer;
  9. import quicktime.app.display.QTCanvas;
  10. import quicktime.app.QTFactory;
  11.  
  12. import quicktime.io.QTFile;
  13.  
  14. /**
  15.  * QTZoo Module 2 - Playing a Movie
  16.  * This application requires QuickTime for Java
  17.  *
  18.  * @author Michael Hopkins
  19.  * @author Levi Brown
  20.  * @author Apple Computer, Inc.
  21.  * @version 1.0.1 10/21/1999
  22.  *
  23.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  24.  *    
  25.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  26.  *                ("Apple") in consideration of your agreement to the following terms, and your
  27.  *                use, installation, modification or redistribution of this Apple software
  28.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  29.  *                please do not use, install, modify or redistribute this Apple software.
  30.  *
  31.  *                In consideration of your agreement to abide by the following terms, and subject
  32.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  33.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  34.  *                reproduce, modify and redistribute the Apple Software, with or without
  35.  *                modifications, in source and/or binary forms; provided that if you redistribute
  36.  *                the Apple Software in its entirety and without modifications, you must retain
  37.  *                this notice and the following text and disclaimers in all such redistributions of
  38.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  39.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  40.  *                Apple Software without specific prior written permission from Apple.  Except as
  41.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  42.  *                are granted by Apple herein, including but not limited to any patent rights that
  43.  *                may be infringed by your derivative works or by other works in which the Apple
  44.  *                Software may be incorporated.
  45.  *
  46.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  47.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  48.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  49.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  50.  *                COMBINATION WITH YOUR PRODUCTS.
  51.  *
  52.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  53.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  54.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  56.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  57.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  58.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59.  *
  60.  * Revision History
  61.  * ---------------------------------------------------------------------------
  62.  * 12/2/99 MSH added slightly better error handling, reformatting and comments 
  63.  *
  64.  */
  65.  
  66. public class Zoo2 extends Frame
  67. {
  68.     static public int WIDTH  = 640;
  69.     static public int HEIGHT = 480;    
  70.  
  71.     /**
  72.      *  Zoo constructor
  73.      *  @param string title of window
  74.      */
  75.     public Zoo2( String s ) 
  76.     {
  77.         super(s);
  78.         
  79.         setResizable( false );                        // we don't want the window to resize
  80.         setBounds( 0, 0, WIDTH, HEIGHT );            // make window 640x480
  81.         
  82.         QTCanvas myQTCanvas = new QTCanvas( QTCanvas.kInitialSize, 0.5F, 0.5F );
  83.         add( myQTCanvas );
  84.         
  85.         try
  86.         {
  87.             QTFile imageFile = new QTFile( 
  88.                 QTFactory.findAbsolutePath( "data/zebra/ZebraBackground.jpg" ));
  89.             
  90.             GraphicsImporterDrawer mapDrawer = new GraphicsImporterDrawer( imageFile );
  91.             myQTCanvas.setClient( mapDrawer, true );
  92.         }
  93.         catch ( IOException e )
  94.         {
  95.             e.printStackTrace();
  96.         }
  97.         catch ( QTException e )
  98.         {
  99.             e.printStackTrace();
  100.         }
  101.  
  102.         addWindowListener( new WindowAdapter()         // anonymous inner class for handling window events
  103.         {
  104.             public void windowClosing( WindowEvent we )
  105.             {
  106.                 QTSession.close();                    // shut down QT and clean up
  107.                 dispose();                            // destroy window
  108.             }
  109.             public void windowClosed( WindowEvent we )
  110.             {
  111.                 System.exit( 0 );                    // exit to shell
  112.             }
  113.         });
  114.     }
  115.     
  116.     /**
  117.      * Main entry point for the application
  118.      */
  119.     public static void main( String[] args )
  120.     {
  121.         try
  122.         {
  123.             QTSession.open();                        // perform native QuickTime initialization
  124.  
  125.             Zoo2 appWindow = new Zoo2( "QTZoo2" );    // create a new application window
  126.         
  127.             appWindow.show();                        // make the window visible
  128.             appWindow.toFront();                    // bring it to the front
  129.         }
  130.  
  131.         catch ( Exception e )                        // handle any exceptions
  132.         {
  133.             QTSession.close();
  134.             e.printStackTrace();
  135.         }
  136.     }        
  137. }
  138.